﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ylevaatus_rike", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(YlevaatusRike))]
    public class YlevaatusRikeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IYlevaatusRike clazz;
        
        public YlevaatusRikeSerializer(IYlevaatusRike clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("rike_nimetus");
            if (clazz.RikeNimetus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.RikeNimetus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : RikeNimetus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("rike_tase");
            if (clazz.RikeTase!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.RikeTase))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : RikeTase");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("rike_lisainfo");
            if (clazz.RikeLisainfo!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.RikeLisainfo))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : RikeLisainfo");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "rike_nimetus")) {
                goto rike_nimetus;
            }
            else {
                if ((Reader.LocalName == "rike_tase")) {
                    goto rike_tase;
                }
                else {
                    if ((Reader.LocalName == "rike_lisainfo")) {
                        goto rike_lisainfo;
                    }
                    else {
                        return;
                    }
                }
            }
        rike_nimetus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ylevaatus_rike>rike_nimetus");
            }
            clazz.RikeNimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("rike_nimetus")).Value;
            goto START;
        rike_tase:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ylevaatus_rike>rike_tase");
            }
            clazz.RikeTase = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("rike_tase")).Value;
            goto START;
        rike_lisainfo:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ylevaatus_rike>rike_lisainfo");
            }
            clazz.RikeLisainfo = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("rike_lisainfo")).Value;
            goto START;
        }
    }
}
